<template>
	<view>
		<view class="search uni-flex" style="align-items: center;margin-bottom:20upx;padding:20upx;background-color:#0A98D5;">
			<view class="uni-flex  bg-white" style="flex: 1;padding: 10upx 30upx;border-radius: 80upx;align-items: center;">
				<input type="text" v-model="searchKey" placeholder="请输入搜索的姓名" style="flex:1" @confirm="search" />
				<text class="uni-icon uni-icon-search" style="color: #999999;font-size: 24px;" @tap="search"></text>
			</view>

		</view>
		<uni-list>
			<uni-list-item v-for="(item,index) in list" :key="index" @click="openDetail(item)" :title="item.realName" :note="item.phone + item.address"></uni-list-item>
		</uni-list>
		<view class="uni-flex" style="justify-content: center;padding: 10upx;">
			{{contentText[loadingType]}}
		</view>
	</view>
</template>

<script>
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	import {
		dateUtils
	} from '@/common/util.js';
	import uniList from "@/components/uni-list/uni-list.vue"
	import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
	var _this;
	export default {
		components: {
			uniList,
			uniListItem,
			uniSearchBar
		},
		data() {
			return {
				searchKey: '',
				list: [],
				exportList: [],
				page: 1,
				rows: 20,
				hasmore: true,
				loadingType: 0,
				index: 0,
				contentText: ["上拉显示更多", "正在加载...", "没有更多数据了"]
			}
		},
		onLoad() {
			_this = this;
		},
		onShow() {
			this.reload();
		},
		onReachBottom() {
			this.page = this.page + 1;
			if (this.loadingType !== 0) {
				return;
			}
			this.loadingType = 1;
			this.load();
		},
		methods: {
			search: function() {
				this.reload();
			},
			reload() {
				this.page = 1;
				this.rows = 20;
				this.list = [];
				this.hasmore = true;
				this.load();
			},
			load: function() {
				uni.showLoading();
				let that = this;
				this.$sendhttp('/Weixin/findUser.dhtml', {
					realName: this.searchKey,
					page: this.page,
					rows: this.rows,
					oid: uni.getStorageSync("userinfo").oid
				}, function(data) {
					that.list = that.list.concat(data.objs);
					that.hasmore = data.hasNext;
					uni.hideLoading();
					uni.stopPullDownRefresh();
				});
			},
			openDetail(item) {
				uni.navigateTo({
					url: "/pages/member-detail/edit-user?p=" + encodeURIComponent(
						JSON.stringify(item)
					)
				});
			}
		},
		onNavigationBarButtonTap(e) {
			_this.exportTableData()
		}
	}
</script>

<style>
	@import "../../common/uni.css";

	page {
		background-color: #EEEEEE;
	}

	.fixed {
		position: fixed;
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: space-between;
		flex-direction: column;
	}

	.flex-sub {
		flex: 1;
	}

	.bg-white {
		background-color: white;
	}
</style>
